package com.shaobufan.museum.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shaobufan.museum.mapper.MomentMapper;
import com.shaobufan.museum.pojo.entity.Moment;
import com.shaobufan.museum.service.MomentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalTime;
import java.util.List;

/**
 * @author 17126
 * @description 针对表【moment(时刻表)】的数据库操作Service实现
 * @createDate 2024-04-08 09:16:50
 */
@Service
public class MomentServiceImpl extends ServiceImpl<MomentMapper, Moment>
        implements MomentService {
    @Resource
    MomentMapper momentMapper;

    /**
     * 添加时刻
     *
     * @param time 时间
     * @return Boolean
     */
    @Override
    public Boolean addMoment(LocalTime time) {
        Moment moment = new Moment();
        moment.setMoment(time);
        int inserted = momentMapper.insert(moment);
        return inserted == 1;
    }

    /**
     * 通过 id搜索时刻
     *
     * @param moId 时刻 id
     * @return Moment
     */
    @Override
    public Moment searchMoment(Integer moId) {
        QueryWrapper<Moment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mo_id", moId);
        return momentMapper.selectOne(queryWrapper);
    }

    /**
     * 获取所有时刻
     *
     * @return List Moment
     */
    @Override
    public List<Moment> getAllMoment() {
        return momentMapper.selectList(null);
    }
}